package com.ymatou.iapi.godmch.testcase;

import java.util.List;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.godmch.parameter.CreateCodeBean;
import com.ymatou.iapi.godmch.parameter.applySupplierBean;
import com.ymatou.iapi.godmch.parameter.bindmchBean;
import com.ymatou.iapi.godmch.parameter.cancelAllAuthShopDesignBean;
import com.ymatou.iapi.godmch.parameter.createIndepMchBean;
import com.ymatou.iapi.godmch.service.CreateCodeCall;
import com.ymatou.iapi.godmch.service.applyAgentCall;
import com.ymatou.iapi.godmch.service.applySupplierCall;
import com.ymatou.iapi.godmch.service.cancelAllAuthShopDesignCall;
import com.ymatou.iapi.godmch.service.createIndepMchCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.shenqi.GodmchManageCallService;
import com.ymttest.database.model.godmch.shop_design_auth;
import com.ymttest.database.model.godmch.shop_design_authExample;
import com.ymttest.database.sqlwapper.godmch.shop_design_authWapper;
/**
*取消所有授权
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_cancelAllAuthShopDesign{
	private static cancelAllAuthShopDesignBean bean;
	private static cancelAllAuthShopDesignCall call;
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("取消所有授权");
	}

	@Before
	public void caseUp() {
		bean=new cancelAllAuthShopDesignBean();
		call=new cancelAllAuthShopDesignCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(call.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	private void check_verify() throws InterruptedException
	{
	    Logger.verifyEquals("200", call.getCode(), "验证返回Code");
		shop_design_authWapper shop_design_authWapper=new shop_design_authWapper();
		shop_design_authExample example=new shop_design_authExample();
		example.createCriteria().andMch_idEqualTo(bean.getMchId());
		List<shop_design_auth> shops=shop_design_authWapper.selectByExample(example);
		shops.stream().forEach(a->{
			Logger.verifyEquals(-1, a.getAuth_state(), "验证Auth_state有效");
		});
		
	}
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_cancelAllAuthShopDesign_001() {
		Logger.start(true,"取消所有授权-平台商户-返回成功");
		try {
			Integer parentMchId=GodmchManageCallService.CreateSellerMch();
			Integer mchId=GodmchManageCallService.CreateSellerMch();
			//渠道商1邀请码
			CreateCodeBean createbean=GodmchManageCallService.InitcreateCodeBeanForAgent(parentMchId);
			CreateCodeCall createcall=GodmchManageCallService.createCodeCall(createbean);
			//绑定关系
			bindmchBean bindmchBean=GodmchManageCallService.InitbindmchBean(mchId, createcall.getCode());
			GodmchManageCallService.bindmchcall(bindmchBean);
			GodmchManageCallService.authShopDesign(mchId,parentMchId);
			
			bean.setMchId(mchId);
			call.setData(bean);
			call.callService();		
			
			check_verify();
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_cancelAllAuthShopDesign_001_2() {
		Logger.start(true,"取消所有授权-平台商户-2个上级-返回成功");
		try {
			Integer parentMchId=GodmchManageCallService.CreateSellerMch();
			Integer parentMchId2=GodmchManageCallService.CreateSellerMch();
			Integer mchId=GodmchManageCallService.CreateSellerMch();
			//渠道商1邀请码
			CreateCodeBean createbean=GodmchManageCallService.InitcreateCodeBeanForAgent(parentMchId);
			CreateCodeCall createcall=GodmchManageCallService.createCodeCall(createbean);
			//绑定关系
			bindmchBean bindmchBean=GodmchManageCallService.InitbindmchBean(mchId, createcall.getCode());
			GodmchManageCallService.bindmchcall(bindmchBean);
			GodmchManageCallService.authShopDesign(mchId,parentMchId);
			
			
			//渠道商2邀请码
			createbean=GodmchManageCallService.InitcreateCodeBeanForAgent(parentMchId2);
			createcall=GodmchManageCallService.createCodeCall(createbean);
			//绑定关系2
			bindmchBean=GodmchManageCallService.InitbindmchBean(mchId, createcall.getCode());
			GodmchManageCallService.bindmchcall(bindmchBean);
			GodmchManageCallService.authShopDesign(mchId,parentMchId2);
			
			bean.setMchId(mchId);
			call.setData(bean);
			call.callService();		
			
			check_verify();
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_cancelAllAuthShopDesign_003() {
		Logger.start(true,"取消授权上级装修-独立商户-返回成功");
		try {
			createIndepMchBean createIndepMchBean=GodmchManageCallService.InitCreateIndepMchBean();
			createIndepMchCall createIndepMchCall=GodmchManageCallService.CreateIndepMchCall(createIndepMchBean);
			applyAgentCall applyAgentCall=GodmchManageCallService.applyAndapproveAgent(createIndepMchCall.getmchId());
			
			//授权装修
			GodmchManageCallService.authShopDesign( applyAgentCall.getAgentId(),createIndepMchCall.getmchId());
			
			bean.setMchId(applyAgentCall.getAgentId());
			call.setData(bean);
			call.callService();			
			
			check_verify();		
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_cancelAllAuthShopDesign_004() {
		Logger.start(true,"取消授权上级装修-独立商户-供货商-返回成功");
		try {
			
			createIndepMchBean createIndepMchBean=GodmchManageCallService.InitCreateIndepMchBean();
			createIndepMchCall createIndepMchCall=GodmchManageCallService.CreateIndepMchCall(createIndepMchBean);
			//申请供货商
			applySupplierBean applySupplierBean=GodmchManageCallService.initApplySupplier(createIndepMchCall.getmchId());
			applySupplierCall applySupplierCall=GodmchManageCallService.applySupplierCall(applySupplierBean);
			//审核
			GodmchManageCallService.approveSupplier(createIndepMchCall.getmchId(), applySupplierCall.getSupplierId());
			
			//授权装修
			GodmchManageCallService.authShopDesign(createIndepMchCall.getmchId(),applySupplierCall.getSupplierId());
			
			bean.setMchId(createIndepMchCall.getmchId());
			call.setData(bean); 
			call.callService();			
			
			check_verify();		
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_cancelAllAuthShopDesign_005() {
		Logger.start(true,"取消授权上级装修-上下级关系不存在-返回失败");
		try {
			Integer parentMchId=GodmchManageCallService.CreateSellerMch();
			Integer mchId=GodmchManageCallService.CreateSellerMch();
			//渠道商1邀请码
			CreateCodeBean createbean=GodmchManageCallService.InitcreateCodeBeanForAgent(parentMchId);
			CreateCodeCall createcall=GodmchManageCallService.createCodeCall(createbean);
			//绑定关系
			bindmchBean bindmchBean=GodmchManageCallService.InitbindmchBean(mchId, createcall.getCode());
			GodmchManageCallService.bindmchcall(bindmchBean);
			GodmchManageCallService.authShopDesign(mchId,parentMchId);
			
			bean.setMchId(parentMchId);
			call.setData(bean);
			call.callService();			
			
		    Logger.verifyEquals("200", call.getCode(), "验证返回Code");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_cancelAllAuthShopDesign_007() {
		Logger.start(true,"取消授权上级装修-商户id为空-返回失败");
		try {
			Integer parentMchId=GodmchManageCallService.CreateSellerMch();
			Integer mchId=GodmchManageCallService.CreateSellerMch();
			//渠道商1邀请码
			CreateCodeBean createbean=GodmchManageCallService.InitcreateCodeBeanForAgent(parentMchId);
			CreateCodeCall createcall=GodmchManageCallService.createCodeCall(createbean);
			//绑定关系
			bindmchBean bindmchBean=GodmchManageCallService.InitbindmchBean(mchId, createcall.getCode());
			GodmchManageCallService.bindmchcall(bindmchBean);
			GodmchManageCallService.authShopDesign(mchId,parentMchId);
			
		//	bean.setMchId(parentMchId);
			call.setData(bean);
			call.callService();				
			
		    Logger.verifyEquals("4001", call.getCode(), "验证返回Code");
		    
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}